package com.cci.kangdao.cipapi;

import com.cci.kangdao.cipFleet.dto.request.CipFleetAndEsnRequest;
import com.cci.kangdao.cipFleet.dto.request.CipFleetCreateRequest;
import com.cci.kangdao.cipFleet.dto.request.CipFleetESNRequest;
import com.cci.kangdao.cipFleet.dto.request.CipFleetUpdateRequest;
import com.cci.kangdao.cipFleet.dto.response.CipEntityResponse;
import com.cci.kangdao.cipFleet.dto.response.CipHealthCheckResponse;
import com.cci.kangdao.cipFleet.dto.response.CipPhcEntityResponse;
import com.cci.kangdao.cipFleet.dto.response.CipSuccessResponse;
import com.cci.kangdao.dao.*;
import com.cci.kangdao.dao.model.UserChannelT;
import com.cci.kangdao.model.FuelBehaviorRecommedInfo;
import com.cci.kangdao.utilTool.HttpUtils;
import com.cci.kangdao.utilTool.JsonUtils;
import com.gexin.fastjson.JSON;
import com.gexin.fastjson.JSONArray;
import com.gexin.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//app同步cip相关接口

/**
 * @ClassName CipServiceApiImpl
 * @Description APP与cip系统Api接口列表
 * @Author 商伟
 * @Date 2022/08/03 11:09 AM
 * @Version 1.0
 **/
@Service("cipServiceApi")
public class CipServiceApiImpl implements CipServiceApi {

	/** 1、日志 */
	private static final Logger LOG = Logger.getLogger(CipServiceApiImpl.class);

	@Value("${fourc.ca.url}")
	private String fourcCaUrl;

	@Value("${fourc.ca.appKey}")
	private String fourcCaAppKey;

	@Value("${fourc.engine.url}")
	private String fourcEngineUrl;

	@Value("${fourc.engine.appKey}")
	private String fourcEngineAppKey;

	@Value("${privilege.url}")
	private String privilegeUrl;

	@Value("${cip.fleetSync.url}")
	private String cipFleetSyncUrl;

	@Value("${cip.fleetSync.appKey}")
	private String cipFleetSyncAppKey;

	@Value("${cip.fuelBehavior.url}")
	private String fuelBehaviorUrl;

	@Value("${cip.fuelBehavior.token}")
	private String fuelBehaviorToken;

	@Value("${url.activity}")
	private String activityUrl;

	@Value("${cip.vip.url}")
	private String fourcVipUrl;

	@Value("${cip.vip.appKey}")
	private String fourcVipAppKey;

	public static final String ESN_UPDATE = "/ca/faultSubscriptionESNUpdate";

	public static final String INFO = "/engine/basicInfo";

	public static final String SYNCBIND = "/xgjForeign/syncBindVehicle";

	public static final String UPDATEFLEETUSERID = "/xgjForeign/updateFleetUserId";

	public static final String ADDFLEETUSERID = "/xgjForeign/addUserInfo";

	public static final String FleetCreate = "/fleet/sync/create";

	public static final String FleetUpdate = "/fleet/sync/update";

	public static final String FleetDel = "/fleet/sync/del";

	public static final String FleetESNAdd = "/fleet/sync/esn/add";

	public static final String FleetESNRemove = "/fleet/sync/esn/remove";
	public static final String HealthCheck = "/phc/healthCheck";
	public static final String fuelBehavior = "/fuelBehaviorRecommed/query";

	public static final String AddNeophyteUser = "/api/neophyte/addNeophyteUser";
	public static final String FinishNeophyteUser = "/api/neophyte/finishTaskByCode";
	@Resource
	private CustomerEngineRelDao customerEngineRelDao;
	@Resource
	private DictionariesTDao  dictionariesTDao;
	@Resource
	private SSRepairTDao ssRepairTDao;
	@Resource
	private CipFleetMapper cipFleetMapper;
	@Resource
	private UserChannelTMapper userChannelTMapper;

	/**
	 * 同步esn
	 * @param action 同步类型
	 * @param esnList
	 * @return
	 */
	@Override
	public void synchronizationEsn(String action, List<String> esnList,String businessNo) {
		try{
			if(StringUtils.isNotBlank(action) && !CollectionUtils.isEmpty(esnList) && esnList.size() > 0){
				String dInt = "0";
				if(StringUtils.isNotBlank(businessNo)){
					Long companyId = ssRepairTDao.getCompanyIdBybusinessNo(businessNo);
					if(null != companyId){
						dInt = String.valueOf(companyId);
					} else {
						dInt = "2";
					}
				}
				String fleetName = dictionariesTDao.getListByDTableNameAndDInt("caFleetName",dInt);
				if(StringUtils.isBlank(fleetName)){
					fleetName = "eCummins_Enduser";
				}
				String url = String.format(fourcCaUrl + ESN_UPDATE);
				CipRequestEntity requestEntity = new CipRequestEntity();
				requestEntity.setAction(action);
				requestEntity.setEsnList(esnList);
				requestEntity.setFleetName(fleetName);
				String jsonString = JSONArray.toJSON(requestEntity).toString();
				Header key = new BasicHeader("app-key", fourcCaAppKey);
				LOG.info("ca同步esn成功；打印参数:" + jsonString + "；url：" + url);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("ca同步esn失败；打印参数:" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					CipResponeEntity respone = JSON.parseObject(response, CipResponeEntity.class);
					LOG.info("ca同步esn成功；打印参数:" + jsonString + "；返回结果：" + respone);
				}
			}
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
	}

	/**
	 * 获取esn
	 * @param esn
	 * @return
	 */
	@Override
	public CipResponeEntity getEsnInfo(String esn) {
		if(StringUtils.isNotBlank(esn)){
			try{
				String url = String.format(fourcEngineUrl + INFO);
				Map<String,String> map = new HashMap();
				map.put("esn",esn);
				String jsonString = JSONArray.toJSON(map).toString();
				Header key = new BasicHeader("app-key", fourcEngineAppKey);
				LOG.info("cip获取esn信息接口地址；打印参数" + jsonString + "；url：" + url);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("cip同步esn失败；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					CipResponeEntity respone = JSON.parseObject(response, CipResponeEntity.class);
					LOG.info("cip获取esn信息成功；打印参数" + jsonString + "；返回结果：" + respone);
					return respone;
				}
			}catch (Exception e){

			}
		}
        return null;
	}

	/**
	 * 绑车数据至芯管家后台
	 * @param request
	 * @return
	 */
	@Override
	public void syncBindVehicle(FleetAndEsnRelationRequest request,Long userId) {
		if(null != request){
			try{
				String url = String.format(privilegeUrl + SYNCBIND);
				String jsonString = JSONArray.toJSON(request).toString();
				LOG.info("绑车数据至芯管家后台地址；打印参数" + jsonString + "；url：" + url);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("绑车数据至芯管家后台失败；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				});
				if (StringUtils.isNotEmpty(response)) {
					XgjResponeEntity respone = JSON.parseObject(response, XgjResponeEntity.class);
					if(!request.getOperate().equals("D") && null != respone && respone.getStatus().equals("0")){
						customerEngineRelDao.updateBusinessNoByNoEsn(request.getEsn(),userId,request.getBusinessNo());
					}
					LOG.info("绑车数据至芯管家后台成功；打印参数" + jsonString + "；返回结果：" + respone);
				}
			}catch (Exception e){

			}
		}
	}

	/**
	 * 技师修改服务站和转终端用户同步芯管家服务站
	 * @param userId
	 * @param stationId
	 */
	@Override
	public void updateXgjFleetUserId(Long userId, Long stationId) {
		try{
			String url = String.format(privilegeUrl + UPDATEFLEETUSERID);
			Map<String,Object> map = new HashMap<>();
			map.put("userId",userId);
			map.put("stationId",stationId);
			String jsonString = JSONArray.toJSON(map).toString();
			LOG.info("技师修改服务站和转终端用户同步芯管家服务站；打印参数" + jsonString + "；url：" + url);
			String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
				@Override
				public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
					if (response.getStatusLine().getStatusCode() == 200
							|| response.getStatusLine().getStatusCode() == 206) {
						HttpEntity httpEntity = response.getEntity();
						return EntityUtils.toString(httpEntity);
					} else {
						LOG.error("技师修改服务站和转终端用户同步芯管家服务站失败；打印参数" + jsonString + "；返回结果：" + response);
					}
					return null;
				}
			});
			if (StringUtils.isNotEmpty(response)) {
				LOG.info("技师修改服务站和转终端用户同步芯管家服务站；打印参数" + jsonString + "；返回结果：" + response);
			}
		}catch (Exception e){
			LOG.info("技师修改服务站和转终端用户同步芯管家服务站；报错" + e);
		}
	}

	/**
	 * 添加芯管家管理员
	 * @param userId
	 * @param stationId
	 */
	@Override
	public void addXgjFleetUserId(Long userId, Long stationId) {
		try{
			String url = String.format(privilegeUrl + ADDFLEETUSERID);
			Map<String,Object> map = new HashMap<>();
			map.put("userId",userId);
			map.put("stationId",stationId);
			String jsonString = JSONArray.toJSON(map).toString();
			LOG.info("添加芯管家管理员；打印参数" + jsonString + "；url：" + url);
			String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
				@Override
				public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
					if (response.getStatusLine().getStatusCode() == 200
							|| response.getStatusLine().getStatusCode() == 206) {
						HttpEntity httpEntity = response.getEntity();
						return EntityUtils.toString(httpEntity);
					} else {
						LOG.error("添加芯管家管理员失败；打印参数" + jsonString + "；返回结果：" + response);
					}
					return null;
				}
			});
			if (StringUtils.isNotEmpty(response)) {
				LOG.info("添加芯管家管理员；打印参数" + jsonString + "；返回结果：" + response);
			}
		}catch (Exception e){
			LOG.info("添加芯管家管理员；报错" + e);
		}
	}

	/**
	 * 添加车队
	 * @param request
	 * @return
	 */
	@Override
	public CipSuccessResponse fleetCreate(CipFleetCreateRequest request) {
		CipSuccessResponse createRespone = new CipSuccessResponse();
		try{
			String url = String.format(cipFleetSyncUrl + FleetCreate);
			LOG.error("添加车队；打印参数" + request+ "；url：" + url);
			if(StringUtils.isNotBlank(request.getFleetName())){
				String jsonString = JSONArray.toJSON(request).toString();
				Header key = new BasicHeader("app-key", cipFleetSyncAppKey);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("添加车队失败；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("添加车队调用成功；打印参数" + jsonString + "；返回结果：" + response);
					CipEntityResponse respone = JSON.parseObject(response, CipEntityResponse.class);
					if(null != respone && "0".equals(respone.getStatus())){
						createRespone = JSON.parseObject(response, CipSuccessResponse.class);
					} else if(null != respone){
						createRespone.setStatus(respone.getStatus());
						createRespone.setMsg(respone.getMsg());
					}
				}
			}
			return createRespone;
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}

	/**
	 * 修改车队
	 * @param request
	 * @return
	 */
	@Override
	public CipEntityResponse fleetUpdate(CipFleetUpdateRequest request) {
		CipEntityResponse cipResponse = new CipEntityResponse();
		try{
			String url = String.format(cipFleetSyncUrl + FleetUpdate);
			LOG.error("修改车队；打印参数" + request+ "；url：" + url);
			if(StringUtils.isNotBlank(request.getFleetName()) && StringUtils.isNotBlank(request.getFleetId())){
				String jsonString = JSONArray.toJSON(request).toString();
				Header key = new BasicHeader("app-key", cipFleetSyncAppKey);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("修改车队失败；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("修改车队调用成功；打印参数" + jsonString + "；返回结果：" + response);
					cipResponse = JSON.parseObject(response, CipEntityResponse.class);
				}
			}
			return cipResponse;
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}

	/**
	 * 删除车队
	 * @param request
	 * @return
	 */
	@Override
	public CipEntityResponse fleetDel(CipFleetUpdateRequest request) {
		CipEntityResponse cipResponse = new CipEntityResponse();
		try{
			String url = String.format(cipFleetSyncUrl + FleetDel);
			LOG.error("删除车队；打印参数" + request+ "；url：" + url);
			if(StringUtils.isNotBlank(request.getFleetId())){
				Map<String,String> map = new HashMap<>();
				map.put("fleetId",request.getFleetId());
				map.put("channel",request.getChannel());
				String jsonString = JSONArray.toJSON(map).toString();
				Header key = new BasicHeader("app-key", cipFleetSyncAppKey);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("删除车队失败；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("删除车队调用成功；打印参数" + jsonString + "；返回结果：" + response);
					cipResponse = JSON.parseObject(response, CipEntityResponse.class);
				}
			}
			return cipResponse;
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}



	/**
	 * 添加车队同步cip
	 * @param request
	 * @return
	 */
	@Override
	public CipSuccessResponse fleetAddCip(CipFleetAndEsnRequest request) {
		CipFleetCreateRequest createRequest = new CipFleetCreateRequest();
		createRequest.setFleetCode(request.getFleetCode());
		createRequest.setFleetName(request.getFleetName());
		String energyType = "";
		if(null!= request.getFleetType() && request.getFleetType() == 0){
			energyType = "GAS";//燃气
		} else if(null!= request.getFleetType() && request.getFleetType() == 1){
			energyType = "FUEL";//燃油
		}
		createRequest.setEnergyType(energyType);
		String applicationType = "";
		if(null!= request.getApplicationType() && request.getApplicationType() == 0){
			applicationType = "OnHighway";//道路
		} else if(null!= request.getApplicationType() && request.getApplicationType() == 1){
			applicationType = "OffHighway";//非道路
		}
		createRequest.setApplicationType(applicationType);
		if(null != request.getServiceChannel() && !"1".equals(request.getServiceChannel())){
			createRequest.setChannel(request.getServiceChannel());
			createRequest.setUserId(request.getExternalUserId());
		} else {
			List<UserChannelT> channelList = userChannelTMapper.getUserChannelListByUserId(Long.valueOf(request.getUserId()));
			if(CollectionUtils.isNotEmpty(channelList)){
				createRequest.setChannel(channelList.get(0).getServiceChannel());
				createRequest.setUserId(channelList.get(0).getExternalUserId());
			} else {
				createRequest.setChannel("1");
				createRequest.setUserId(request.getUserId());
			}
		}
		List<CipFleetESNRequest> esnList = new ArrayList<>();
		if(CollectionUtils.isNotEmpty(request.getEsnList())){
			for(CipFleetAndEsnRequest.EsnRequest esn : request.getEsnList()){
				CipFleetESNRequest esnRequest = new CipFleetESNRequest();
				esnRequest.setEsn(esn.getEsn());
				esnRequest.setPlateNumber(esn.getPlateNumber());
				esnList.add(esnRequest);
			}
		}
		createRequest.setEsnList(esnList);
		CipSuccessResponse response = this.fleetCreate(createRequest);
		return response;
	}

	/**
	 * 修改车队同步cip
	 * @param request
	 * @return
	 */
	@Override
	public CipEntityResponse fleetUpdateCip(CipFleetAndEsnRequest request) {
		CipFleetUpdateRequest updateRequest = new CipFleetUpdateRequest();
		updateRequest.setFleetId(request.getCipFleetId());
		updateRequest.setFleetCode(request.getFleetCode());
		updateRequest.setFleetName(request.getFleetName());
		String energyType = "";
		if(null!= request.getFleetType() && request.getFleetType() == 0){
			energyType = "GAS";//燃气
		} else if(null!= request.getFleetType() && request.getFleetType() == 1){
			energyType = "FUEL";//燃油
		}
		updateRequest.setEnergyType(energyType);
		String applicationType = "";
		if(null!= request.getApplicationType() && request.getApplicationType() == 0){
			applicationType = "OnHighway";//道路
		} else if(null!= request.getApplicationType() && request.getApplicationType() == 1){
			applicationType = "OffHighway";//非道路
		}
		updateRequest.setApplicationType(applicationType);
		if(null != request.getServiceChannel() && !"1".equals(request.getServiceChannel())){
			updateRequest.setChannel(request.getServiceChannel());
			updateRequest.setUserId(request.getExternalUserId());
		} else {
			List<UserChannelT> channelList = userChannelTMapper.getUserChannelListByUserId(Long.valueOf(request.getUserId()));
			if(CollectionUtils.isNotEmpty(channelList)){
				updateRequest.setChannel(channelList.get(0).getServiceChannel());
				updateRequest.setUserId(channelList.get(0).getExternalUserId());
			} else {
				updateRequest.setChannel("1");
				updateRequest.setUserId(request.getUserId());
			}
		}
		List<CipFleetESNRequest> esnList = new ArrayList<>();
		if(CollectionUtils.isNotEmpty(request.getEsnList())){
			for(CipFleetAndEsnRequest.EsnRequest esn : request.getEsnList()){
				CipFleetESNRequest esnRequest = new CipFleetESNRequest();
				esnRequest.setEsn(esn.getEsn());
				esnRequest.setPlateNumber(esn.getPlateNumber());
				esnList.add(esnRequest);
			}
		}
		updateRequest.setEsnList(esnList);
		List<String> labelList = cipFleetMapper.getFleetLabel(request.getFleetId());
		if(CollectionUtils.isNotEmpty(labelList)){
			updateRequest.setFleetLabel(String.join(",", labelList));
		}
		CipEntityResponse response = this.fleetUpdate(updateRequest);
		return response;
	}

	/**
	 * 删除车队同步cip
	 * @param fleetId
	 * @return
	 */
	@Override
	public CipEntityResponse fleetDeleteCip(String fleetId,String serviceChannel,Long userId) {
		CipFleetUpdateRequest request = new CipFleetUpdateRequest();
		request.setFleetId(fleetId);
		if(null != serviceChannel && !"1".equals(serviceChannel)){
			request.setChannel(serviceChannel);
		} else {
			List<UserChannelT> channelList = userChannelTMapper.getUserChannelListByUserId(userId);
			if(CollectionUtils.isNotEmpty(channelList)){
				request.setChannel(channelList.get(0).getServiceChannel());
			} else {
				request.setChannel("1");
			}
		}
		CipEntityResponse response = this.fleetDel(request);
		return response;
	}

	/**
	 * 调用cip返回车辆健康评分
	 * @param esn
	 * @return
	 */
	@Override
	public CipHealthCheckResponse getCipHealthCheck(String esn) {
		CipHealthCheckResponse healthCheckResponse = new CipHealthCheckResponse();
		try{
			String url = String.format(fourcEngineUrl + HealthCheck);
			LOG.info("获取车辆健康评分；打印参数" + esn + "；url：" + url);
			if(StringUtils.isNotBlank(esn)){
				Map<String,String> map = new HashMap<>();
				map.put("esn",esn);
				String jsonString = JSONArray.toJSON(map).toString();
				Header key = new BasicHeader("app-key", fourcEngineAppKey);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("获取车辆健康评分；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("获取车辆健康评分；打印参数" + jsonString + "；返回结果：" + response);
					CipPhcEntityResponse respone = JSON.parseObject(response, CipPhcEntityResponse.class);
					if(null != respone && "0".equals(respone.getCode())){
						healthCheckResponse = JsonUtils.toJavaObject(respone.getData().toString(), CipHealthCheckResponse.class);
					}
				}
			}
			return healthCheckResponse;
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}

	/**
	 * 调用cip同步油耗驾驶行为建议信息
	 * @param info
	 * @return
	 */
	@Override
	public CipPhcEntityResponse syncFuelBehaviorRecommed(FuelBehaviorRecommedInfo info) {
		CipPhcEntityResponse cipPhcEntityResponse = new CipPhcEntityResponse();
		try{
			String url = String.format(fuelBehaviorUrl + fuelBehavior);
			LOG.error("同步油耗驾驶行为建议信息；打印参数" + info + "；url：" + url);
			if(null != info){
				String jsonString = JSONArray.toJSON(info).toString();
				Header key = new BasicHeader("token", fuelBehaviorToken);
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("同步油耗驾驶行为建议信息；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				}, key);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("同步油耗驾驶行为建议信息；打印参数" + jsonString + "；返回结果：" + response);
					//cipPhcEntityResponse = JSON.parseObject(response, CipPhcEntityResponse.class);
				}
			}
			return cipPhcEntityResponse;
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}
	/**
	 * 调用activity添加新手活动
	 * @param userId
	 */
	@Override
	public void addNeophyteUser(Long userId) {
		try{
			String url = String.format(activityUrl + AddNeophyteUser);
			LOG.info("添加新手活动；打印参数userId:" + userId);
			if(null != userId){
				Map<String,Object> map = new HashMap<>();
				map.put("userId",userId);
				String jsonString = JSONArray.toJSON(map).toString();
				String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("添加新手活动；打印参数" + jsonString + "；返回结果：" + response);
						}
						return null;
					}
				});
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("添加新手活动；打印参数" + jsonString + "；返回结果：" + response);
				}
			}
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
	}


	/**
	 * 调用activity完成新手活动
	 * @param taskCode
	 */
	@Override
	public void finishNeophyteTaskUser(String taskCode, String params, String userid,String authorization) {
		try{
			String url = String.format(activityUrl + FinishNeophyteUser);
			LOG.info("完成新手活动；打印参数userId:" + userid + ";taskCode:" + taskCode);
			if(null != userid && null != taskCode){
				List<NameValuePair> parameter = new ArrayList<>();
				parameter.add(new BasicNameValuePair("taskCode",taskCode));
				parameter.add(new BasicNameValuePair("params",params));
				Header headerAuthorization = new BasicHeader("Authorization", authorization);
				Header headerUserid = new BasicHeader("userid", userid);
				String response = HttpUtils.postForm(url, parameter, new ResponseHandler<String>() {
					@Override
					public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
						if (response.getStatusLine().getStatusCode() == 200
								|| response.getStatusLine().getStatusCode() == 206) {
							HttpEntity httpEntity = response.getEntity();
							return EntityUtils.toString(httpEntity);
						} else {
							LOG.error("完成新手活动；打印参数" + parameter.toString() + "；返回结果：" + response);
						}
						return null;
					}
				},headerAuthorization,headerUserid);
				if (StringUtils.isNotEmpty(response)) {
					LOG.info("完成新手活动；打印参数" + parameter.toString() + "；返回结果：" + response);
				}
			}
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
	}

	/**
	 * 获取vip数据
	 * @param request
	 * @return
	 */
	@Override
	public CipRespone getPostDataByCipUrl(VipRequest request) {
		CipRespone vipResponse = new CipRespone();
		try{
			String url = String.format(fourcVipUrl + request.getUrl());
			String jsonString = JSONObject.toJSONString(request.getMap());
			LOG.info("获取vip数据；打印参数" + jsonString + "；url：" + url);
			Header appKey = new BasicHeader("appKey", fourcVipAppKey);
			String response = HttpUtils.postJson(url, jsonString, new ResponseHandler<String>() {
				@Override
				public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
					if (response.getStatusLine().getStatusCode() == 200
							|| response.getStatusLine().getStatusCode() == 206) {
						HttpEntity httpEntity = response.getEntity();
						return EntityUtils.toString(httpEntity);
					} else {
						LOG.info("获取vip数据；打印参数" + jsonString + "；返回结果：" + response);
					}
					return null;
				}
			},appKey);
			if (StringUtils.isNotEmpty(response)) {
				LOG.info("获取vip数据；打印参数" + jsonString + "；返回结果：" + response);
				CipReturnResponse returnResponse = JsonUtils.toJavaObject(response, CipReturnResponse.class);
				if(returnResponse.getCode().equals("0")){
					CipResponeEntity baseResponse = JsonUtils.toJavaObject(response, CipResponeEntity.class);
					if(null != baseResponse.getData()){
						vipResponse = JsonUtils.toJavaObject(baseResponse.getData().toString(), CipRespone.class);
					}
				}
				return vipResponse;
			}
		}catch (Exception e){
			LOG.error(e.getMessage(), e);
		}
		return null;
	}

}
